package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 发布评论
     */
    @PostMapping
    public ResponseEntity postComments(@RequestBody Map map){
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        commentService.postComments(movementId,comment);
        return ResponseEntity.ok(null);
    }
    /**
     * 分页查询评论列表
     */
    @GetMapping
    public ResponseEntity commentsList(String movementId,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = commentService.movementList(movementId,page,pagesize);
        return ResponseEntity.ok(pr);
    }
    /**
     * 评论点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity commentLike(@PathVariable("id") String commentId){
        Integer count = commentService.likeComment(commentId);
        return ResponseEntity.ok(count);
    }

    /**
     * 评论取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity commentdisLike(@PathVariable("id") String commentId){
        Integer count = commentService.dislikeComment(commentId);
        return ResponseEntity.ok(count);
    }

}
